1 using UnityEngine;
2 using
System.Collections;
3
4 public
class NextPrevClickListener : InputAdapter {
5
6     
public BigAnimals bigAnimals;
7     
public int buttonIndex;
8     
public ShopScreen shopScreen;
9
10     
public void Start()
11     {
12         
13     }
14
15     
public override void OnTouchDown()
16     {
17         
if (InputController.Name != InputNames.SHOP) return;
18         
base.OnTouchDown();
19         gameObject.transform.localScale =
new Vector3(0.9f, 0.9f, gameObject.transform.localScale.z);
20         SoundManager.playButtonSound();
21     }
22     
public override void OnCheckUp()
23     {
24         
if (InputController.Name != InputNames.SHOP) return;
25         
base.OnCheckUp();
26         gameObject.transform.localScale =
new Vector3(1, 1, gameObject.transform.localScale.z);
27     }
28     
public override void OnTouchUp()
29     {
30         
if (InputController.Name != InputNames.SHOP) return;
31         
base.OnTouchUp();
32         
if (buttonIndex == 0)//prev
33         {
34             bigAnimals.setAnimalIndex(prevIndex(Attr.currentAnimal));
35         }
36         
else//next
37         {
38             bigAnimals.setAnimalIndex(nextIndex(Attr.currentAnimal));
39         }
40         shopScreen.updateAnimalName();
41         shopScreen.updateUI();
42     }
43
44     
private int prevIndex(int animalIndex)
45     {
46         
int temp = animalIndex;
47         temp--;
48         
if (temp == -1)
49             temp =
9;
50         
return temp;
51     }
52
53     
private int nextIndex(int animalIndex)
54     {
55         
int temp = animalIndex;
56         temp++;
57         
if (temp == 10)
58             temp =
0;
59         
return temp;
60     }
61 }


if (buttonIndex == 0)prev

elsenext




Trò chơi đua xe động vật trong UNITY Engine 114.805 lượt xem

Gõ tìm kiếm nhanh...